package edu.ynu.se.xiecheng.achitectureclass.controller;

import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import edu.ynu.se.xiecheng.achitectureclass.dao.GreenHouseDao;
import edu.ynu.se.xiecheng.achitectureclass.dto.GreenHouseDTO;
import edu.ynu.se.xiecheng.achitectureclass.entity.GreenHouse;
import edu.ynu.se.xiecheng.achitectureclass.service.GreenHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/greenhouses")
public class GreenHouseController extends LogicController<GreenHouseService, GreenHouseDao, GreenHouse,Long> {

    private final GreenHouseService greenHouseService;

    @Autowired
    public GreenHouseController(GreenHouseService greenHouseService) {
        super(greenHouseService);
        this.greenHouseService = greenHouseService;
    }

    @GetMapping
    public ResponseEntity<List<GreenHouseDTO>> getAllGreenHouses() {
        List<GreenHouseDTO> greenHouseDTOs = greenHouseService.getAllGreenHousesDTO();
        return new ResponseEntity<>(greenHouseDTOs, HttpStatus.OK);
    }
}
